package mini.statement;

import java.util.HashMap;
import java.util.LinkedList;

import mini.Proc;
import mini.StatementList;
import mini.expr.Element;
import mini.expr.Expr;


public class RepeatStatement extends Statement {

    private Expr expr;
    private StatementList sl;

    public RepeatStatement(StatementList list, Expr e) {
        expr = e;
        sl = list;
    }

    public void eval(HashMap<String, Element> nametable, HashMap<String, Proc> functiontable, LinkedList var) throws Exception {
        Element val = expr.eval(nametable, functiontable, var);
        
        if (!val.isInt()) {
        	throw new IllegalArgumentException("Parse error. Expression does not evaluate to an int.");
        }
        
		do {
            sl.eval(nametable, functiontable, var);
        } while (expr.eval(nametable, functiontable, var).getIntValue() > 0);

    }
}